package expbase

import (
	"encoding/json"
	"gitee.com/wudicaidou/menciis-pocx/pocbase"
	"net/http"
)

const (
	TypeOsInfo  = "os"
	TypePhpInfo = "php"
)

type EventBase struct {
	Target *pocbase.TargetInfo
	Plugin *pocbase.PluginInfo
}

type BasicInfoEvent struct {
	EventBase
	Request  http.Request
	Response http.Response
	// 这里的 type 一定是上面定义的类型之一，一个 event 只会有一种类型的 info
	// 比如 type 是 os，那么下方的 OSInfo 就是数据，其他字段可以忽略
	Type string

	Os  *OSInfo
	Php *PhpInfo
}

func (b *BasicInfoEvent) String() string {
	return b.Type
}

func (b *BasicInfoEvent) MarshalJSON() ([]byte, error) {
	return json.Marshal(b)
}

type FileDownloadEvent struct {
	EventBase
	Request  http.Request
	Response http.Response
	Filename string
	Content  []byte
}

func (f *FileDownloadEvent) String() string {
	return f.Filename
}

func (f *FileDownloadEvent) MarshalJSON() ([]byte, error) {
	return json.Marshal(f)
}

type CommandResultEvent struct {
	EventBase
	Request  http.Request
	Response http.Response
	Command  string
	Result   []byte
}

func (c *CommandResultEvent) String() string {
	return c.Command
}

func (c *CommandResultEvent) MarshalJSON() ([]byte, error) {
	return json.Marshal(c)
}
